package com.aiju.cash.ui.setting;

import android.os.Bundle;
import android.view.View;

import com.aiju.app.DataProviderManager;
import com.aiju.base.activity.BaseTitleActivity;
import com.aiju.cash.R;
import com.aiju.utils.PreferencesUtils;
import com.aiju.widgit.layout.SettingItemRadioButton;

/**
 * @author: 佐为
 * @date: 2017-03-08 15:51
 * @version: V1.0
 * @Description: 收款设置
 */
public class PaySettingActivity extends BaseTitleActivity {

    private SettingItemRadioButton radioButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setCenterTitle("收款设置");
        setContentView(R.layout.activity_pay_setting);

        findViewById(R.id.ly_tts).setSelected(PreferencesUtils.getBoolean(this, "tts", true));
        //findViewById(R.id.ly_vibrator).setSelected(PreferencesUtils.getBoolean(this, "vibrator", true));

        findViewById(R.id.ly_tts).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                v.setSelected(!v.isSelected());
                PreferencesUtils.putBoolean(PaySettingActivity.this, "tts", v.isSelected());
            }
        });


        findViewById(R.id.ly_vibrator).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                v.setSelected(!v.isSelected());
                PreferencesUtils.putBoolean(PaySettingActivity.this, "autoPrint", v.isSelected());
            }
        });
        int printSum = PreferencesUtils.getInt(DataProviderManager.getContext(), "printSum", 1);

        radioButton = (SettingItemRadioButton) findViewById(R.id.set_print);
        radioButton.getleftView().getPaint().setFakeBoldText(true);
        radioButton.setRadio1Text("1联");
        radioButton.setRadio2Text("2联");
        radioButton.setRadioGroupCheck(String.valueOf(printSum));
        radioButton.setChangeListener(new SettingItemRadioButton.OnChangeListener() {
            @Override
            public void change(String item) {
                if (item.equals("1")) {
                    PreferencesUtils.putInt(PaySettingActivity.this, "printSum", 1);
                } else {
                    PreferencesUtils.putInt(PaySettingActivity.this, "printSum", 2);
                }
            }
        });
        boolean autoPrint = PreferencesUtils.getBoolean(this, "autoPrint");
        findViewById(R.id.ly_vibrator).setSelected(autoPrint);
    }
}
